package com.mutual.assistance.task;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import java.util.*;
import java.util.concurrent.TimeUnit;

/**
 * @author chenyuxin
 * @version 1.0
 * @description TODO
 * @date 2023/5/7 23:24
 */
@Component
public class test {

    private static StringRedisTemplate stringRedisTemplate = null;

    @Autowired
    public test(StringRedisTemplate stringRedisTemplate) {
        test.stringRedisTemplate = stringRedisTemplate;
    }

    public static void main(String[] args) {
       /* Set<Integer> set = new HashSet<>();
        set.add(1);
        set.add(2);
        set.add(3);
        set.add(4);
        set.add(5);
        String jsonString = JSON.toJSONString(set);
        System.out.println(jsonString);
        Set<Integer> object = JSON.parseObject(jsonString, new TypeReference<Set<Integer>>() {});
        System.out.println(object);*/

        List<String> list = Arrays.asList("日用品", "二手书", "跑腿", "求助", "求大神指导", "吃瓜", "二手交易", "太难了", "泰酷啦", "又懂又懂", "入股不亏",
                "秀儿，是你吗", "干就完事了", "我太南了", "内牛满面", "破防", "企业级理解", "顶级理解", "真香", "元芳，你怎么看？"
                , "五块钱以下的活动别叫我", "躺着也中枪", "上头", "slb");
        stringRedisTemplate.opsForValue().set("666666","我是test", 2, TimeUnit.MINUTES);
        /*Set<String> setString = new HashSet<>(list);
        System.out.println(setString);
        Set<Integer> set = new HashSet<>();
        set.add(1);
        set.add(5);
        set.add(7);
        System.out.println("获取到集合：" + JSON.toJSONString(set));
        parseSetInteger(JSON.toJSONString(set), list);*/
    }

    public static void parseSetInteger(String intSet,  List<String> list) {
        System.out.println("后台开始处理");
        Set<Integer> object = JSON.parseObject(intSet, new TypeReference<Set<Integer>>() {});
        StringJoiner stringJoiner = new StringJoiner(",");
        for (Integer integer : object) {
            stringJoiner.add(list.get(integer));
        }
        String returnTap = stringJoiner.toString();
        System.out.println("输出结果：" + returnTap);
        System.out.println("后台处理结束");
    }

    public static void parseSetArray(String intSet,  List<String> list) {
        System.out.println("后台开始处理");
        Set<Integer> sets = JSON.parseObject(intSet, new TypeReference<Set<Integer>>() {});
        List<String> arrays = new ArrayList<>();
        for (Integer set : sets) {
            arrays.add(list.get(set));
        }
        System.out.println("输出结果集合：" + arrays);
        System.out.println("输出结果字符串：" + JSON.toJSONString(arrays));
        System.out.println("后台处理结束");
    }
}
